﻿
namespace FolderSync
{
    using System;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Linq;

    public class RegExpFileFilter : FolderSync.IFileFilter
    {
        public Regex rd { get; set; }
        public Regex rf { get; set; }
        public Regex xd { get; set; }
        public Regex xf { get; set; }
        public bool Match(string FolderFullName, string FileName)
        {
            return MatchFolder(FolderFullName) && MatchFile(FileName);
        }
        public bool MatchFolder(string FolderFullName)
        {
            var tree=FolderFullName.Split(new char[] { '\\' });
            return tree.Any(f => (rd == null || rd.Match(f).Success))
                && tree.All(f => (xd == null || !xd.Match(f).Success));
        }
        public bool MatchFile(string FileName)
        {
            return (rf == null || rf.Match(FileName).Success)
                && (xf == null || !xf.Match(FileName).Success);
        }
    }
}
